package daobeauty.interceptor.returntype.handler.impl;

import java.util.List;

import daobeauty.interceptor.returntype.handler.ReturnTypeHandler;

/**
 * ReturnTypeHandler for methods returning a single object, that is none of the supported Collection types.
 * 
 * @author M. Serhat Cinar
 *
 */
public class BooleanReturnType implements ReturnTypeHandler<Boolean> {

	/**
	 * Returns null, if the given List is empty, or the first element of the list.
	 * 
	 * @see daobeauty.interceptor.returntype.handler.ReturnTypeHandler#convert(java.util.List)
	 */
	@SuppressWarnings("unchecked")
	public Boolean convert(List result) {
		return false;
	}

	/**
	 * Returns the given object as is.
	 * 
	 * @see daobeauty.interceptor.returntype.handler.ReturnTypeHandler#convert(java.lang.Object)
	 */
	@SuppressWarnings("unchecked")
	public Boolean convert(Object result) {
		if (Boolean.class.isAssignableFrom(result.getClass())){
			return ((Boolean)result);
		}
		return false;
	}
}
